﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using System.Data;
using ClassLibrary.Entity;

namespace ClassLibrary.DAO
{
    public class TblTinTucSuKienDAO
    {
        private DBService _db = null;
        public TblTinTucSuKienDAO(String ConnectionString)
        {
            _db = new DBService(ConnectionString);
        }

        public DataTable InsUpTinTucSuKien(TblTinTucSuKien tintuc, int mode)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("sp_TblTinTucSuKien_InsUp",
                    new string[] {"@ID", "@Datetime", "@TieuDe", "@NoiDung",  "@Image" , "@NoiDungTomTat", "@Mode" },
                    new object[] { tintuc.ID, tintuc.Datetime, tintuc.TieuDe, tintuc.NoiDung, tintuc.Image, tintuc.NoiDungTomTat, mode}, CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable GetTinTucSK()
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("select * from TblTinTucSuKien", false, CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable GetTinTucSK_ByID(int id)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("select * from TblTinTucSuKien where ID = @id", new string[] { "@id" }, new object[] { id }, CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

    }
}
